package cn.hfatec.shms.web.members.ykLog.service;

import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.base.BaseDao;
import cn.hfatec.shms.web.members.ykLog.dao.YkLogDao;
import cn.hfatec.shms.web.members.ykLog.model.YkLog;
import cn.hfatec.shms.web.members.ykLog.model.YkLogParams;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;


/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("YkLogService")
public class YkLogService {

    public static final String BEAN_ID = "YkLogService";

    //注入Dao层
    @Resource(name = "YkLogDao")
    private YkLogDao ykLogDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param ykLogParams
     * @param page
     *
     */
    @Transactional
    public Table queryYkLogTable(YkLogParams ykLogParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", ykLogParams);
        return baseDao.queryTableByPage("queryYkLog", params, page);
    }

    /**
     *
     * 插入数据
     * @param ykLog
     *
     */
    @Transactional
    public void saveYkLog(YkLog ykLog) {
        if(ykLog.getLogId() != null) {
            YkLog result = getYkLog(ykLog.getLogId());
            if(result != null) {
                ykLogDao.update(ykLog);
            } else {
                ykLogDao.insert(ykLog);
            }
        } else {
            ykLogDao.insert(ykLog);
        }
    }

    /**
     *
     * 删除数据
     * @param logId
     *
     */
    @Transactional
    public void deleteYkLog(Integer logId) {

        ykLogDao.delete(logId);
    }

    /**
     *
     * 删除数据
     * @param ykLogList
     *
     */
    @Transactional
    public void deleteYkLogBatch(List<String> ykLogList) {
        for(String logId : ykLogList) {
            deleteYkLog(Integer.valueOf(logId));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param logId
     *
     */
    @Transactional
    public YkLog getYkLog(Integer logId) {

        return ykLogDao.getYkLogByLogId(logId);
    }
}